package gg.com.toolbox.adapter;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.HashMap;

import gg.com.toolbox.R;
import gg.com.toolbox.bean.SecrecyBean;

/**
 * 账号列表适配器
 * Created by gaoge on 2017/10/10.
 */

public class NotepadAdapter extends BaseAdapter {
    private LayoutInflater lf = null;
    private ArrayList<SecrecyBean> list = null;
    private Activity activity = null;

    public NotepadAdapter(Activity activity, ArrayList<SecrecyBean> list) {
        lf = LayoutInflater.from(activity);
        this.activity = activity;
        this.list = list;
    }

    public void setData(ArrayList<SecrecyBean> data) {
        this.list = data;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressLint("InflateParams")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = lf.inflate(R.layout.notepad_list_item, null);
            holder = new ViewHolder();
            holder.title = (TextView) convertView.findViewById(R.id.title);
            holder.username = (TextView) convertView.findViewById(R.id.username);
            holder.password = (TextView) convertView.findViewById(R.id.password);
            holder.remarks = (TextView) convertView.findViewById(R.id.remarks);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.title.setText(list.get(position).getTitle());
        holder.username.setText("账号："+list.get(position).getUserName());
        holder.password.setText("密码："+list.get(position).getPassWord());
        holder.remarks.setText("备注："+list.get(position).getRemarks());
        return convertView;
    }

    private class ViewHolder {
        private TextView title = null;
        private TextView username = null;
        private TextView password = null;
        private TextView remarks = null;
    }
}

